/* test code */
#include "timerlib.h"
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

static int count = 0;

void timer_handler(void* arg)
{
    printf("%s\n", (char*)arg);
    count++;

    return;
}

int main()
{
    int      ret     = 0;
    int      TimerId = 0;
    sigset_t sigset;

    sigemptyset(&sigset);
    sigaddset(&sigset, SIGALRM);
    pthread_sigmask(SIG_BLOCK, &sigset, NULL);

    ret = TimerInit();
    if (ret < 0) {
        printf("Timer init error\n");
        return -1;
    }

    TimerAdd(6, 0, &timer_handler, "This is TimerTest 1", &TimerId);
    TimerAdd(3, 0, &timer_handler, "This is TimerTest 2", &TimerId);
    TimerAdd(1, 0, &timer_handler, "This is TimerTest 3", &TimerId);
    TimerAdd(10, 0, &timer_handler, "This is TimerTest 4", &TimerId);
    TimerAdd(0, 2000, &timer_handler, "This is TimerTest 5", &TimerId);
    TimerAdd(1, 2000, &timer_handler, "This is TimerTest 6", &TimerId);

    while (1) {
        if (count == 6) {
            break;
        }
        usleep(1000);
    }
    TimerDestroy();

    return 0;
}
